<template>
  <div id="BacWorkFlowNodeDict">
    <Breadcrumb content="流程节点字典" />
    <div class="bodyContent">
      <el-tabs type="border-card">
        <el-tab-pane label="流程节点字典">
          <Splitpanes class="area">
            <Pane size="75">
              <vxe-toolbar perfect>
                <template #buttons>
                  <span class="smallToolTitle">名称模糊查找:</span>
                  <vxe-input
                    v-model="form.antName"
                    placeholder="名称"
                    class="vxeInputSearch"
                    type="text"
                    clearable
                    @clear="findAntibioticsDictPageList"
                  ></vxe-input>
                  <vxe-button
                    type="text"
                    icon="vxe-icon-search"
                    class="button-blue SearchBtn"
                    content="查询"
                    :loading="loading"
                    @click="findAntibioticsDictPageList"
                  ></vxe-button>
                  <vxe-button
                    type="text"
                    class="button-blue"
                    icon="vxe-icon-add"
                    content="新增"
                    @click="addBacGerm"
                  ></vxe-button>
                  <vxe-button
                    type="text"
                    icon="vxe-icon-delete"
                    class="button-red"
                    content="删除"
                    @click="handleDelete"
                  ></vxe-button>
                </template>
              </vxe-toolbar>
              <div class="tableBox">
                <vxe-table
                  ref="antibioticsDictTable"
                  border="inner"
                  align="left"
                  class="mytable-scrollbar"
                  height="auto"
                  :data="bacWorkFlowNodeDictList"
                  :expand-config="{ expandAll: true, reserve: true }"
                  :row-config="{ isCurrent: true, isHover: true }"
                  :keyboard-config="{
                    isArrow: true,
                    isTab: true,
                    isEdit: true
                  }"
                  :edit-config="{ trigger: 'dblclick', mode: 'row', showStatus: true }"
                  resizable
                  show-overflow
                  keep-source
                  @current-change="roleRowClick"
                >
                  <vxe-column type="checkbox" width="30px"></vxe-column>
                  <vxe-column field="nodeTypeNa" title="节点类型" width="60"></vxe-column>
                  <vxe-column field="code" title="编码" width="80"></vxe-column>
                  <vxe-column field="name" title="名称" min-width="120"></vxe-column>
                  <vxe-column field="seq" title="序号" width="60"></vxe-column>
                  <vxe-column field="displayFlag" title="显示标志" width="100"></vxe-column>
                  <vxe-column field="displayColor" title="显示颜色" width="80">
                    <template #default="{ row }">
                      <el-color-picker v-model="row.displayColor" />
                    </template>
                  </vxe-column>
                  <vxe-column field="standardName" title="编号前缀" width="80"></vxe-column>
                  <vxe-column field="codePrefix" title="编号规则编码" width="100"></vxe-column>
                  <vxe-column field="isPrintLabel" title="是否打印标签" width="90"></vxe-column>
                  <vxe-column field="isEnable" title="是否启用" width="80"></vxe-column>
                </vxe-table>
              </div>
            </Pane>
            <Pane size="25">
              <el-tabs type="border-card">
                <el-tab-pane label="基本信息">
                  <!-- 流程节点字典 基本信息表单-->
                  <BacWorkFlowNodeDictForm
                    ref="refFormData"
                    @getTableData="findAntibioticsDictPageList"
                  />
                </el-tab-pane>
              </el-tabs>
            </Pane>
          </Splitpanes>
        </el-tab-pane>
        <el-tab-pane label="操作日志">
          <LogInfo requestUrl="/lis/resistantType"></LogInfo>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
// 引入组件区 ==========
import Breadcrumb from '@/components/Breadcrumb.vue';
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import { pageSizes, formatDateTime } from '@/utils/common';
import { Splitpanes, Pane } from 'splitpanes';
import { AppStore } from '@/stores/store';
import XEUtils from 'xe-utils';
import { VXETable } from 'vxe-table';
import { VxeNotifyType, VxeMessage } from '@/utils/CommonMessage';
import BacWorkFlowNodeDictForm from './BacWorkFlowNodeDictForm.vue'; //检验仪器基本信息表单
import LogInfo from '@/components/LogInfo.vue'; //日志

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let store = AppStore();
let form = reactive({
  antName: '' //名称
});

let bacWorkFlowNodeDictList: any[] = reactive([]); //流程节点字典列表

let loading = ref(false); //查询按钮加载

let saveLoading = ref(false);

let refFormData: any = ref(null); //信息表单ref

// 方法定义区 =============

// 页面加载时
onMounted(() => {
  findAntibioticsDictPageList(); //获取检验仪器表格数据
});

// 获取检验仪器表格数据
function findAntibioticsDictPageList() {
  loading.value = true;
  bacWorkFlowNodeDictList.length = 0;
  const url = '/api/bac/bac-work-flow-node-dict/findBacWorkFlowNodeDictList';
  proxy.$http
    .get(url, {
      params: {
        pageSize: page.pageSize,
        pageIndex: page.currentPage,
        searchValue: form.antName
      }
    })
    .then((res: any) => {
      bacWorkFlowNodeDictList.push(...res.data);
      roleRowClick({
        row: bacWorkFlowNodeDictList[0],
        rowIndex: 0
      });
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('搜索流程节点字典列表异常', VxeNotifyType.error);
    });
}

// 新增微生物
function addBacGerm() {
  const $formRef = refFormData.value;
  refFormData.value.addNew();
}

//删除按钮
function handleDelete() {
  const selectRows = (proxy.$refs.antibioticsDictTable as any).getCheckboxRecords();
  if (selectRows.length <= 0) {
    VxeMessage('请勾选需要删除的数据', VxeNotifyType.warning);
    return;
  } else {
    proxy
      .$confirm('您确定要删除当前选中的这条数据吗?', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        const data = { bacWorkFlowNodeDicts: selectRows };
        const url = '/api/bac/bac-work-flow-node-dict/deleteBacWorkFlowNodeDict';
        proxy.$http
          .post(url, data)
          .then((res: any) => {
            findAntibioticsDictPageList();
            refFormData.value.clearFormData(); //调用子组件的清空表单方法
            VxeMessage(res.status.msg, VxeNotifyType.success);
          })
          .catch((err: any) => {
            VxeMessage(err, VxeNotifyType.error);
          });
      });
  }
}

// 点击表格当前行
function roleRowClick({ row, rowIndex }: any) {
  refFormData.value.initPage(row); //传递给右侧基本信息表单
  (proxy.$refs.antibioticsDictTable as any).setCurrentRow(row);
}

//点击每页数量
function handleSizeChange({ type, currentPage, pageSize }) {
  if (type === 'size') {
    page.currentPage = 1;
  } else {
    page.currentPage = currentPage;
  }
  page.pageSize = pageSize;
  findAntibioticsDictPageList();
}

//下拉选择之后触发保存当前
function selectchange(e: any) {
  e.aimKeys.forEach((item: any) => {
    if (e.isChild) {
      instrSetupList[e.childIndex][item.targetField] = e.row[item.sourceField];
      if (item.targetField === 'reportUnitEntity') {
        instrSetupList[e.childIndex].groupNo = e.row[item.sourceField].id;
      }
    } else {
      //表单用
    }
  });
}

//这个月第一天日期
function getThisMonthFirstDay() {
  let today = new Date();
  today.setDate(1);
  today.setHours(0, 0, 0, 0);
  return today;
}

//当前日期
function getThisMonthNewDay() {
  let today = new Date();
  return today;
}

function formatOperateTime({ cellValue, row, column }) {
  // 假设cellValue是一个时间戳，你可以使用Date对象将其格式化为包含毫秒的形式
  const date = new Date(cellValue);
  return formatDateTime(date, 'yyyy-MM-dd hh:mm:ss.SSS'); // 这会返回包含毫秒的 ISO 8601 格式的时间字符串
}
</script>

<style lang="scss" scoped>
#BacWorkFlowNodeDict {
  height: 100%;

  .bodyContent {
    height: calc(100% - 60px);

    .el-tabs {
      height: 100%;

      :deep(.el-tabs__content) {
        height: calc(100% - 39px);
        padding: 0px;

        .el-tab-pane {
          height: 100%;
        }
      }
    }

    .area {
      background-color: $base-white;
    }

    // 附加按钮间距
    .button-blue,
    .button-red {
      margin: 5px 0 5px 5px;
    }

    // 查询按钮
    .SearchBtn {
      margin-right: 5px;
    }

    .tableBox {
      height: calc(100% - 40px);

      .vxe-table {
        height: 100%;

        :deep(.vxe-table--render-wrapper) {
          height: 100%;

          .vxe-table--main-wrapper {
            height: 100%;

            .vxe-table--body-wrapper {
              height: calc(100% - 26px) !important;
            }
          }
        }
      }
    }
  }
}
</style>
